﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

using Weazel.Badger.Vhdl.Types;

namespace Weazel.Badger.Vhdl.Expressions
{
  public enum AggregateAssociations
  {
    Positional,
    Named,
    SetAll,
    Range
  };

  public class AggregateExpression : Expression
  {
    private AggregateAssociations association;
    private string value;
    private Signal signal;

    public AggregateExpression(
			IComponent parentContainer,
			AggregateAssociations association, 
			Signal signal, 
			string value
		) 
			: base(parentContainer, signal.Type, signal.GezelType)
    {
      this.association = association;
      this.value = value;
      this.signal = signal;
    }

    private Expression to;
    private Expression from;

    public AggregateExpression(
			IComponent parentContainer,
			Signal signal, 
			Expression to, 
			Expression from
		) 
			: base(parentContainer, signal.Type, signal.GezelType)
    {
      this.signal = signal;
      this.to = to;
      this.from = from;
    }

		public override void SetActualType(
			Entity entity, 
			Process process, 
			Statements.StatementCollection statements, 
			Vhdl.Types.Type type
		)
    {      
      this.Type = type;
    }

    public override TypeSet GetPossibleTypes()
    {
			string message =
				"GetPossibleTypes(): Should not be called on AggregateExpression";

      throw new NotSupportedException(message);
    }


    public override bool VerifyType(ref List<VerifyMessage> messages)
    {
      throw new NotImplementedException();
    }


    public override string ToString()
    {
      switch (association)
      {
        case AggregateAssociations.Range:
          return string.Format("({1} Downto {2})", to.ToString(), from.ToString());

        case AggregateAssociations.SetAll:
          return String.Format("(others => {0})", value.ToString());

        default:
          throw new NotImplementedException();
      }
    }
  }
}
